WT_DECLARE_WT_MEMBER(3,JavaScriptConstructor,"ScrollVisibility",function(g){function l(a){if(a.style.visibility=="hidden"||a.style.display=="none"||$(a).hasClass("out"))return false;else return(a=a.parentNode)&&!n.hasTag(a,"BODY")?l(a):true}function o(a,c){if(!l(a))return false;var e=n.widgetPageCoordinates(a),d=e.x-document.body.scrollLeft-document.documentElement.scrollLeft;e=e.y-document.body.scrollTop-document.documentElement.scrollTop;var f=n.windowSize(),r=a.offsetHeight,p=-c,s=f.x+2*c,q=-c;
c=f.y+2*c;return d+a.offsetWidth>=p&&p+s>=d&&e+r>=q&&q+c>=e}function h(){if(i)for(var a in b){if(b.hasOwnProperty(a)){var c=l(b[a].el);if(b[a].visibleIfNotHidden&&b[a].visible!==c){b[a].visible=c;g.emit(b[a].el,"scrollVisibilityChanged",c)}}}else for(a in b)if(b.hasOwnProperty(a)){c=o(b[a].el,b[a].margin);if(c!==b[a].visible){b[a].visible=c;g.emit(b[a].el,"scrollVisibilityChanged",c)}}}function t(a){for(var c=0;c<a.length;++c){var e=a[c],d=e.target,f=d.id;d=l(d);if(e.intersectionRatio>0||e.intersectionRect.top!==
0||e.intersectionRect.left!==0){b[f].visibleIfNotHidden=true;if(b[f].visible!==d){b[f].visible=d;g.emit(b[f].el,"scrollVisibilityChanged",d)}}else{b[f].visibleIfNotHidden=false;if(b[f].visible){b[f].visible=false;g.emit(b[f].el,"scrollVisibilityChanged",false)}}}}function u(){if(j){j.observe(document,{childList:true,attributes:true,subtree:true,characterData:true});if(!i){window.addEventListener("resize",h,true);window.addEventListener("scroll",h,true)}}else m=setInterval(h,100)}function v(){if(j){j.disconnect();
if(!i){window.removeEventListener("resize",h,{capture:true});window.removeEventListener("scroll",h,{capture:true})}}else if(m){clearInterval(m);m=null}}var n=g.WT,k=0,b={},i=false,j=null,m=null;if(window.hasOwnProperty("MutationObserver"))j=new MutationObserver(h);this.add=function(a){k===0&&u();var c=a.el.id,e=c in b;i&&e&&b[c].observer&&b[c].observer.disconnect();var d=o(a.el,a.margin);if(a.visible!==d){a.visible=d;g.emit(a.el,"scrollVisibilityChanged",d)}b[c]=a;if(i){d=new IntersectionObserver(t,
{rootMargin:""+a.margin+"px"});d.observe(a.el);b[c].observer=d}e||++k};this.remove=function(a){if(k!==0){if(a in b){i&&b[a].observer&&b[a].observer.disconnect();delete b[a];--k}k===0&&v()}}});
